package com.hopu.erp.service.impl;

import com.hopu.erp.dao.RoleDAO;
import com.hopu.erp.entity.PageEntity;
import com.hopu.erp.entity.Role;
import com.hopu.erp.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleServiceImpl implements RoleService {

    @Autowired
    private RoleDAO roleDAO;

    @Override
    public List<Role> findRolesByUsername(String username) {
        return roleDAO.selectRolesByUsername(username);
    }

    @Override
    public PageEntity<Role> findRolesPage(Integer current) {
        int count = roleDAO.selectRolesCount();
        int pageCount = count % PageEntity.PAGE_SIZE == 0 ? count / PageEntity.PAGE_SIZE : count / PageEntity.PAGE_SIZE + 1;
        List<Role> data = roleDAO.selectRolesPage((current - 1) * PageEntity.PAGE_SIZE, PageEntity.PAGE_SIZE);
        return new PageEntity<>(data,current,count,pageCount);
    }
}
